
// 模拟封装的请求
export const requestStep = (data, {progress}) => {
    console.log(data)
    console.log(progress)
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                errList: [data[3], data[5]]
            })
        }, 1000)
    });
};

/**
 * 切片处理函数
 * @param {Array} dataArray 所有数据
 * @param {Number} stepLen 一次处理个数
 * @param {Function} handle 处理函数
 * @param {Function} cb 处理完成的回调
 */
export const cutHandle = (dataArray, stepLen, handle, cb) => {
    const result = [];
    const runHandle = (sliceIndex) => {
        let stepArray = dataArray.slice(sliceIndex, (sliceIndex += stepLen));
        if (stepArray.length === 0) {
            cb(result);
            return;
        }
        handle(stepArray, {
            progress: Math.min(1, sliceIndex / dataArray.length)
        }).then((resp) => {
            result.push(resp);
            runHandle(sliceIndex);
        });
    };
    runHandle(0);
};

// 测试数组
export const testArray = new Array(100).fill(0).map((item, index) => index);
// 分片上传回调
export const resultRequest = (result) => {
    console.log(result);
}
